<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 实现trim方法 去除字符串首尾的空格
    function trim(str) {
      return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
    }

    var str = ' aaa aaa aa bb ';
    console.log(str);
    console.log(trim(str));

  </script>
</body>

</html>